import { defineStore, storeToRefs } from "pinia"

import { reqHomeBannerApi, reqInterestApi, reqSortListApi } from "../api/lxcApi"
import type { item } from "../utils/types/lxcTypes"

export const userStore = defineStore({
	id: "homeStore",
	state: () => ({
		videoCardData: [{} as item],
		dialogData: [],
	}),
	getters: {},
	actions: {
		async getHomeBanner() {
			let res = await reqHomeBannerApi()
			this.videoCardData = res.content
		},
		async getSortList() {
			let result = await reqSortListApi()
			// console.log(result);
			return result.content
		},
		async getInterest(num: number) {
			let res = await reqInterestApi(num)
			res.data.content.forEach((ele) => {
				ele.isSelected = false
			})
			this.dialogData = this.dialogData.concat(res.data.content)
			// console.log("dialog数据", this.dialogData)
		},
		fixHomeVideoCardData() {
			// console.log("aciton执行但是不能改变数据", this.videoCardData)
			// this.$patch((state) => {
			// 	state.videoCardData = []
			// })
			// console.log("aciton执行但是不能改变数据", this.videoCardData)
			// this.$patch((state) => {
			// 	state.videoCardData = []
			// })
			// let addfive = this.videoCardData.slice(0, 6)
			// let subfive = this.videoCardData.slice(6)
			// console.log("修改之前", this.videoCardData)
			// let newV = subfive.push(...addfive)
			// this.videoCardData = newV
			// console.log("修改之后", this.videoCardData)
			// this.videoCardData = []

			let fronfive = this.videoCardData.splice(0, 6)
			this.videoCardData.push(...fronfive)
		},
	},
})
